package com.ss.SmartStock.controller.admin;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.ss.SmartStock.common.BaseContext;
import com.ss.SmartStock.common.ErrorCode;
import com.ss.SmartStock.exception.BusinessException;
import com.ss.SmartStock.pojo.dto.operate.OperateQueryRequest;
import com.ss.SmartStock.pojo.entity.Log;
import com.ss.SmartStock.pojo.entity.Operation;
import com.ss.SmartStock.service.LogService;
import com.ss.SmartStock.service.OperationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.parameters.RequestBody;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * @author TsingFeng
 * @date 2024/6/20 13:46
 */
@Slf4j
@RestController
@Api(tags = "操作记录管理接口")
@RequestMapping("/admin/operate")
public class OperateController {

    @Resource
    OperationService operationService;
    @Resource
    private LogService logService;

    /**
     * 分页查询操作记录
     */

    @GetMapping("/list")
    @ApiOperation("分页查询操作记录")
    public IPage<Operation> listProductVOByPage(@RequestBody OperateQueryRequest operateQueryRequest, HttpServletRequest httpServletRequest) {
        if (operateQueryRequest == null) throw new BusinessException(ErrorCode.PARAMS_ERROR);

        log.info("分页查询:{}", operateQueryRequest);
        Log log = Log.builder()
                .userId(BaseContext.getCurrentId())
                .logLevel("INFO")
                .message("分页查询")
                .build();
        logService.save(log);

        long current = operateQueryRequest.getCurrent();
        long size = operateQueryRequest.getPageSize();

        return operationService.selectPageOperations(current,size);
    }



}